<template>
  <el-dialog
    v-dialogDrag
    title="提示"
    :visible.sync="isViewShortWindows"
    width="70%"
    @close="close"
    :append-to-body="true"
    :close-on-click-modal="false"
    @opened="open"
    center
    ref="isPopWindows"
  >
    <dialogHeader
      slot="title"
      title="缺件导入"
      :style-type="$store.state.app.dialogType"
    />
    <div class="formBoxContain">
      <!--
            buttons: 按钮
            froms: 表单
            fromsField: 表单对应的字段
            tableOption: 网格项
            dynamicApiConfigs: 取值
         -->

      <one-table-template
        ref="multipleTable"
        :dynamic-buttons="tableButtons"
        :dynamic-components="tableComponents"
        :dynamic-api-config="dynamicApiConfigs"
        :dynamic-table-cols="tableCols"
        :dynamic-table-defult-height="400"
        :dynamic-form-fields="formField"
        :dynamic-is-show-select="true"
        :dynamic-is-init-table="true"
        :dynamic-is-show-more-btn="true"
        :callbackObj="callbackObj"
        :isShowPagination="true"
      />
    </div>
  </el-dialog>
</template>

<script>
import dialogHeader from "@/components/dialogHeader";
import OneTableTemplate from "@/components/templates/oneTable";
import api from "@/api/vehicleManagement";
import { vehiclePdiPriceInquirys } from "@/api/se/vehiclePdiPriceInquiry";
import { exportExcel } from "@/utils/getTimeString.js";

export default {
  components: {
    dialogHeader,
    OneTableTemplate,
  },
  props: {
    // 是否关闭弹窗
    isViewShortWindows: {
      type: Boolean,
      default: false,
    },
    // 已经选择过的数据
    shortList: { type: Array, default: () => ([]) }
  },
  data() {
    selectiondata: null;
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);
    return {
      dynamicApiConfigs: vehiclePdiPriceInquirys.queryLackPartList,
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
              {
                compKey: "compKey1",
                labelName: "紧急类型：",
                codeField: "a",
                component: () => import("@/components/org/LookupValue"),
                oFields: "statusId,statusText",
                options: [
                  { statusId: "", statusText: "全部" },
                  { statusId: "0", statusText: "一般紧急" },
                  { statusId: "1", statusText: "三包紧急" },
                ],
                type: "dropdownList",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey2",
                labelName: "派工单号：",
                codeField: "associationNo",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                span: 6,
              },
              {
                compKey: "compKey3",
                labelName: "客户名称：",
                codeField: "customerName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                span: 6,
              },
              {
                compKey: "compKey4",
                labelName: "车牌号：",
                codeField: "carLicense",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                span: 6,
              },
              {
                compKey: "compKey5",
                labelName: "缺件单号：",
                codeField: "lackPartsDCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false,
                span: 6,
              },
              {
                compKey: "compKey6",
                labelName: "登记人：",
                codeField: "registerPerson",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false,
                span: 6,
              },
              {
                compKey: "compKey7",
                labelName: "审核时间：",
                codeField: "startDate,endDate",
                lookuptype: "VE0207",
                // component: () =>
                //   import("@/components/org/datePicker/andtDatePicker"),
                component: () => import('@/components/org/datePicker/datePicker'),
                dateType: 'daterange',
                type: "inputText",
                isMust: false,
                span: 6,
              },
            ],
            
      formField: this.$utils.getFormField(this, {
        associationNo: "", //派工单号
        customerName: "", //客户名称
        carLicense: "", //车牌号
        lackPartsDCode: "", //缺件单号
        registerPerson: "", //登记人
        startDate: "", //审核日期
        endDate: "",
      }),
      // 回调方法对象
      callbackObj: {
        // 网格点击回调事件
        onRowClick: (currentRow) => {
          // this.onRightRowClick(currentRow);
        },
        // 手动勾选网格时，拿到勾选网格的数据
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection;
        },

      },
      tableButtons: [
        {
          compKey: "button1",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.open(),
          text: "查询",
          position: "right",
        },
        {
          compKey: "button1",
          type: "primary",
          size: "small",
          name: "submit",
          clickEvent: () => this.notarize(),
          text: "确认",
          position: "right",
        },
        {
          compKey: "button6",
          size: "small",
          // clickEvent: () => this.$refs.isViewShortTable.reset(),
          clickEvent: () => this.$refs.multipleTable.reset(),
          text: "重置",
          position: "right",
        },
      ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "lackPartsDCode",
                label: "缺件单号",
                align: "center",
              },
              {
                prop: "partNo",
                label: "备件号",
                align: "center",
              },
              {
                prop: "partName",
                label: "缺件名称",
                align: "center",
              },
              {
                prop: "lackQty",
                label: "缺件数",
                align: "center",
              },
              {
                prop: "minPurchasePage",
                label: "最小订货数",
                align: "center",
              },
              {
                prop: "expectedDeliveryDate",
                label: "希望到货日期",
                align: "center",
              },
              {
                // prop: "partPrice",
                prop: "purPrice",
                label: "单价",
                align: "center",
              },
              {
                // prop: "lackAmount",
                prop: "purAmount",
                label: "订货金额",
                align: "center",
              },
              {
                prop: "registerPerson",
                label: "登记人",
                align: "center",
              },
              // {
              //   prop: "oemAuditDate",
              //   label: "缺件审核时间",
              //   align: "center",
              // },
              // {
              //   prop: "repairOrderCode",
              //   label: "派工单号+",
              //   align: "center",
              // },
              // {
              //   prop: "vin",
              //   label: "VIN码+",
              //   align: "center",
              // },
              // {
              //   prop: "carLicense",
              //   label: "车牌号+",
              //   align: "center",
              // },
              // {
              //   prop: "custName",
              //   label: "客户名称+",
              //   align: "center",
              // },
              // {
              //   prop: "custTel",
              //   label: "客户电话+",
              //   align: "center",
              // },
            ],
    };
  },
  methods: {
    /**
     * @description 关闭弹窗
     * @time 2021、01、22
     */
    close() {
      this.$refs.multipleTable.reset()
      this.$emit("close");
    },
    open() {
      const queryObj = {
        // 保存mutation
        type: "mutation",
        // api配置
        apiConfig: vehiclePdiPriceInquirys.queryLackPartList,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: this.formField,
      };
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj);
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then((response) => {
        // this.formField = response.rows[0].partOrder[0];
        this.$refs.multipleTable.list = response.rows;
        this.$refs.multipleTable.pageTotal = response.records
      });
    },
    // 确认
    notarize() {
      this.$emit("selectiondata", this.selectiondata);
      this.isViewShortWindows = false;
    },
    // 禁用上个弹窗已选择 数据
    getSelectable(row, index, ref) {
      return !this.shortList.includes(row['partNo'])
    },
  },
};
</script>
<style scoped>

</style>
